package org.example.Servlet.pwd;

import cn.hutool.json.JSONUtil;
import org.example.Dao.PersonDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/fw/fd")
public class ForwardPwdServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String email = req.getParameter("email");
        String password = req.getParameter("password");
        System.out.println(email + " " + password);
        PersonDao personDao = new PersonDao();
        try {
            int count = personDao.updatePwd(email, password);
            if (count > 0) {
                resp.getWriter().write(JSONUtil.toJsonStr("success"));
            }else {
                resp.getWriter().write(JSONUtil.toJsonStr("error"));
            }
        } catch (Exception e) {
            System.out.println("forward password error ==> " + e.getMessage());
        }

    }
}
